// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import NodeUtil from "../../Utils/NodeUtil";
import PoolUtil from "../../Utils/PoolUtil";

const {ccclass, property} = cc._decorator;

enum animState {
    None = 0,
    BackOut,
}


@ccclass
export default class DialogBase extends cc.Component {

    //打开弹窗的动画
    @property(cc.Node)
    content: cc.Node = null;
    // 自定义枚举，下拉框属性，中文显示
    @property({
        type: cc.Enum(animState),
        displayName: "动画"
    })
    anim = animState.None;

    private _popName: string = "";
    public set popName(url:string) {this._popName=url}
    /** 弹窗prefab路径，规则同Res加载路径 */
    public get popName(): string { return this._popName; }

    
    @property({ tooltip: CC_DEV && "关闭弹窗时是否缓存弹窗节点", })
    protected cache: boolean = false;
    
    protected onLoad(): void {

    }
    protected onEnable(): void {
        if(this.anim&&this.content){
            this.content.scale=0;
            cc.tween(this.content).to(0.5,{scale:1},cc.easeBackOut()).start();
        }
    }

    close(){
        if (this.cache) {
            PoolUtil.put(this.popName, this.node);
        } else {
            this.node.removeFromParent();
            this.node.destroy();
        }
    }
}
